package java8_24;

/**
 * @author oldliu
 * @since 1.0
 */
public class Teacher {
    private String name;
    private int age;//年龄,不能小于20岁

    public Teacher(){

    }

    public Teacher(String name, int age) {
        this.name = name;
        //this.age = age;
        //if(age<20||age>60)
        this.setAge(age);//构造方法可以调用成员方法，反过来一般不行
    }

    //写入的方法
    public void setName(String n){
        this.name=n;
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int a){
        if(a<20||a>60){
            System.out.println("这个老师too young!");
            return;
        }
        this.age=a;
    }
    public void show() {
        System.out.println("老师叫" + name + ",今年" + age + "岁");
    }
}
